<?php
//引用登录弹窗
    include("login.php");
//引用注册弹窗
    include("regist.php");
?>

<header class="p-header new-header p-header-show">
<div class="first-nav">
    <style>
        .login_{
            width: 200px;
            float: right;
        }
        .login_first{
            width: 50%;
            text-align: center;
        }
        .login_ed{
            width: 30%;
            text-align: center;
        }
        .login_right{
            float: right;
        }
        .login_div:hover{
            cursor: pointer;
            background-color: rgb(214, 211, 211);
            color:rgb(243, 128, 128);
        } 
    </style>
    <?php

            if(!isset($_SESSION['username'])){
                echo '
                <style>.login_ed{display:none;}</style>
                ';
            }
            else{
                echo '
                <style>.login_first{display:none;}</style>
                ';
            }
        ?>  
    <div class="login_">
        <div class="login_div login_first login_right" onclick="user_regist()">注册</div>
        <div class="login_div login_first" onclick="user_login()">请先登录</div>

        <div class="login_div login_ed login_right" onclick="logout()" >退出登录</div>
        <div class="login_div login_ed" onclick="location.href='/my.php'" >个人中心</div>

    </div>
</div>
</header>
<script>
    //弹出注册框
    function user_regist(){
        $(".regist_shadow").css("display","block");
    }
    //关闭注册弹窗
    function close_regist(){
    $(".regist_shadow").css("display","none");
    }
    //弹出登录框
    function user_login(){
        $(".login_shadow").css("display","block");
    }
    //关闭弹窗
    function close_login(){
    $(".login_shadow").css("display","none");
    }
    
    //登出
    function logout(){
        $.post(
                "/controler.php",
                {
                    handle:"logout",
                },
                function(msg){
                    if(msg=="done"){
                        // $(".login_first").css("display","block");
                        // $(".login-tip").css("display","block");
                        // $(".login_ed").css("display","none");
                        // $(".wantcomment").css("display","none");
                        location.reload();
                    }
                    else{
                        alert("系统出错");
                    }
                }
            )
        }
</script>